/**
 * 
 */
package net.fdukedom.epicurus.pm.domain.entity;

import java.util.Date;

import net.fdukedom.epicurus.domain.entity.User;

/**
 * @author Sergey Vishnyakov
 *
 */
public class PrivateMessage {
    
    /**
     * PM id. 
     */
    private int id;
    
    /**
     * Author of PM.
     */
    private User from;
    
    /**
     * Recepient of PM.
     */
    private User to;

    /**
     * Title of PM.
     */
    private String title;
    
    /**
     * Body of PM.
     */
    private  String body;
    
    /**
     * PM creation date.
     */
    private Date created = new Date();
    
    /**
     * If PM was read by recepient.
     */
    private boolean isRead = false;

    
    /**
     * Default constructor (required by Hibernate).
     */
    public PrivateMessage() {
        
    }
    
    /**
     * @return the body
     */
    public String getBody() {
        return body;
    }

    /**
     * @param body the body to set
     */
    public void setBody(String body) {
        this.body = body;
    }

    /**
     * @return the created
     */
    public Date getCreated() {
        return created;
    }

    /**
     * @param created the created to set
     */
    public void setCreated(Date created) {
        this.created = created;
    }

    /**
     * @return the from
     */
    public User getFrom() {
        return from;
    }

    /**
     * @param from the from to set
     */
    public void setFrom(User from) {
        this.from = from;
    }

    /**
     * @return the id
     */
    public int getId() {
        return id;
    }

    /**
     * @param id the id to set
     */
    public void setId(int id) {
        this.id = id;
    }

    /**
     * @return the title
     */
    public String getTitle() {
        return title;
    }

    /**
     * @param title the title to set
     */
    public void setTitle(String title) {
        this.title = title;
    }

    /**
     * @return the to
     */
    public User getTo() {
        return to;
    }

    /**
     * @param to the to to set
     */
    public void setTo(User to) {
        this.to = to;
    }

    /**
     * @return the isRead
     */
    public boolean getIsRead() {
        return isRead;
    }

    /**
     * @param isRead the isRead to set
     */
    public void setIsRead(boolean isRead) {
        this.isRead = isRead;
    }

    /* (non-Javadoc)
     * @see java.lang.Object#hashCode()
     */
    @Override
    public int hashCode() {
        final int PRIME = 31;
        int result = 1;
        result = PRIME * result + ((body == null) ? 0 : body.hashCode());
        result = PRIME * result + ((created == null) ? 0 : created.hashCode());
        result = PRIME * result + ((from == null) ? 0 : from.hashCode());
        result = PRIME * result + id;
        result = PRIME * result + (isRead ? 1231 : 1237);
        result = PRIME * result + ((title == null) ? 0 : title.hashCode());
        result = PRIME * result + ((to == null) ? 0 : to.hashCode());
        return result;
    }

    /* (non-Javadoc)
     * @see java.lang.Object#equals(java.lang.Object)
     */
    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        final PrivateMessage other = (PrivateMessage) obj;
        if (body == null) {
            if (other.body != null)
                return false;
        } else if (!body.equals(other.body))
            return false;
        if (created == null) {
            if (other.created != null)
                return false;
        } else if (!created.equals(other.created))
            return false;
        if (from == null) {
            if (other.from != null)
                return false;
        } else if (!from.equals(other.from))
            return false;
        if (id != other.id)
            return false;
        if (isRead != other.isRead)
            return false;
        if (title == null) {
            if (other.title != null)
                return false;
        } else if (!title.equals(other.title))
            return false;
        if (to == null) {
            if (other.to != null)
                return false;
        } else if (!to.equals(other.to))
            return false;
        return true;
    }
}
